/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package listeners.table;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JTable;
import model.generic.TableModelWithListeners;

/**
 *
 * @author Dirk
 */
public class TableKeyListener implements KeyListener {
    
    private TableModelWithListeners model;
    private JTable table;

    public TableKeyListener(TableModelWithListeners model, JTable table) {
        this.model = model;
        this.table = table;
    }
    
    @Override
    public void keyTyped(KeyEvent e) {
        //DO NOTHING
    }

    @Override
    public void keyPressed(KeyEvent e) {
       //DO NOTHING
    }

    @Override
    public void keyReleased(KeyEvent e) {
        int selected = table.getSelectedRow();
        if(e.getKeyCode() == KeyEvent.VK_DELETE && selected > -1){
            table.getCellEditor().stopCellEditing();
            model.removeItem(table.convertRowIndexToModel(selected));
        }
        
    }
    
}
